package com.xpffly.design.observer.common;

import com.xpffly.design.observer.common.service.Observer;
import com.xpffly.design.observer.common.service.impl.*;

/**
 * @Author: 午夜学徒
 * @Date: 2022/4/3 12:48
 * @Description：观察者模式通用代码场景类
 */
public class Scene {
    public static void main(String[] args) {
        // 定义股票主题
        StockSubject stockSubject = new StockSubject();
        // 定义期货主题
        FuturesSubject futuresSubject = new FuturesSubject();
        // 定义观察者
        Observer observer1 = new Observer1();
        Observer observer2 = new Observer2();
        Observer observer3 = new Observer3();
        Observer observer4 = new Observer4();
        // 添加股票主题的 观察者
        stockSubject.addObserver(observer1);
        stockSubject.addObserver(observer2);
        stockSubject.addObserver(observer3);
        stockSubject.addObserver(observer4);
        // 添加期货主题的观察者
        futuresSubject.addObserver(observer1);
        futuresSubject.addObserver(observer3);
        // 股票主题---信息更新
        stockSubject.doSomething();
        // 期货主题---信息更新
        futuresSubject.doSomething();
    }
}
